<?php
/**
 * @Author: anchen
 * @Date:   2017-05-17 19:36:45
 * @Last Modified by:   anchen
 * @Last Modified time: 2017-10-04 14:30:54
 */

//初始化文件


//拒绝非法访问
defined('ACCESS_KEY9296')||exit('denied');

define('DEBUG',true);
//初始化当前的绝对路径
define('ROOT',str_replace('\\','/',dirname(dirname(__FILE__))).'/');


//设置报错级别
if(defined('DEBUG')){
    error_reporting(E_ALL);
}
else{
   error_reporting(0);
}
error_reporting(E_ALL ^ E_DEPRECATED);
/*require(ROOT.'include/db.class.php');
require(ROOT.'include/mysql.class.php');
require(ROOT.'Model/Model.class.php');
require(ROOT.'Model/TestModel.php');
require(ROOT.'include/conf.class.php');
require(ROOT.'include/log.class.php');
*/
require(ROOT.'include/lib_base.php');

session_start();
function __autoload($class){
    if(strtolower(substr($class,-5)) == 'model'){
        //echo ROOT . 'Model/'.$class.'.class.php';
        require(ROOT . 'Model/'.$class.'.class.php');
    }
    else{
        require(ROOT . 'include/'.$class.'.class.php');
    }
}
function upload() {
        $upload = new UploadFile();
        $upload->saveRule = 'time';
        $upload->maxSize  = 3145728 ;
        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');
        $upload->savePath =  './Uploads/';
        if(!$upload->upload()) {
            return false;
        }
        else{
            $info=$upload->getUploadFileInfo();
            $img_path="/Uploads/".$info[0]['savename'];
            import('ORG.Util.Image');
            Image::water("./Uploads/".$info[0]['savename'],'./Uploads/logo.png');
            echo $img_path;
            return $img_path;
        }
}




function ajaxReturn($data,$info='',$status=1,$type='') {
        $result  =  array();
        $result['status']  =  $status;
        $result['info'] =  $info;
        $result['data'] = $data;
        if(strtoupper($type)=='JSON') {
            // 返回JSON数据格式到客户端 包含状态信息

        }elseif(strtoupper($type)=='XML'){
            // 返回xml格式数据
            header("Content-Type:text/xml; charset=utf-8");
            exit(xml_encode($result));
        }
    }


function pages($pageNum = 1, $pageSize = 9,$class=null)
{
    $array = array();
    $mysql = mysql::getIns();
    if($class==null){
        $rs = "SELECT * FROM cake order by cake_date desc LIMIT ".(($pageNum - 1)* $pageSize).",".$pageSize;
    }
    else{
        $rs = "SELECT * FROM cake WHERE cake_class=$class order by cake_date desc LIMIT ".(($pageNum - 1)* $pageSize).",".$pageSize;
    }

    $r = $mysql->query( $rs);
    while($row = mysql_fetch_array($r)){
        $array[] = $row;
    }
return $array;
}

function allNews(){
    $array = array();
    $mysql = mysql::getIns();
    $rs = "select count(*) num from cake";
    $r = $mysql->query($rs);
    //var_dump($r);
    while($row = mysql_fetch_array($r)){
    $array = $row;
    }
    //var_dump($array);
    return $array['num'];
}


//过滤参数,递归方式过滤
$_GET = _addslashes($_GET);
$_POST = _addslashes($_POST);
$_COOKIE = _addslashes($_COOKIE);



